<template>
  <div>
    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
      <div class="widget am-cf">
        <div class="widget-head am-cf">
          <div class="widget-title am-fl">回访记录</div>
        </div>
        <div class="widget-body  am-fr">
          <customer-toolbar
            ref="toolbar"
            class="toolbar"
            @search="handleFind"
            @export="handleExport"
            areaTeam
            campusTeam
            studentName
            phoneNo
            visitTime
            visitOperatorName
            haveReg
            recycleTime
            hasExport
          ></customer-toolbar>
          <div class="am-u-sm-12">
            <el-table
              :data="tableData"
              border
              empty-text="暂无数据"
              stripe
              style="min-width: 100%"
            >
              <el-table-column
                min-width="100"
                prop="studentName"
                label="学生姓名"
              >
              </el-table-column>
              <el-table-column
                min-width="120"
                prop="studentNo"
                label="学生学号"
              >
              </el-table-column>
              <el-table-column
                min-width="130"
                prop="phoneNo"
                label="电话号码"
              >
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="gradeName"
                label="年级"
              >
              </el-table-column>
              <el-table-column
                min-width="100"
                label="紧急程度"
              >
                <template scope="scope">
                  <div>{{{'0' : '低' ,'1': '中', '2': '高'}[scope.row.priority]}}</div>
                </template>
              </el-table-column>
              <el-table-column
                min-width="150"
                prop="willRegCampusName"
                label="意向校区"
              >
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="visitOperatorName"
                label="回访人"
              >
              </el-table-column>
              <el-table-column
                min-width="170"
                prop="visitTime"
                label="回访时间"
              >
                <template scope="scope">
                  <div>{{scope.row.visitTime | formatTime}}</div>
                </template>
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="visitWay"
                label="回访形式"
              >
                <template scope="scope">
                  <div>{{{'0' : '电话' ,'1': '直访', '2': '其他方式'}[scope.row.visitWay]}}</div>
                </template>
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="willRegPossible"
                label="报读意愿"
              >
                <template scope="scope">
                  <div>{{{'0' : '一般' ,'1': '强烈', '2': '无意愿'}[scope.row.willRegPossible]}}</div>
                </template>
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="willRegSubjectName"
                label="意向科目"
              >
              </el-table-column>
              <el-table-column
                min-width="120"
                prop="willRegRegLevel"
                label="意向班型"
              >
                <template scope="scope">
                  <div>{{scope.row.willRegRegLevel | getRegLevelVal}}</div>
                </template>
              </el-table-column>
              <!-- <el-table-column
                min-width="100"
                prop="isCameToCampus"
                label="是否到店">
                <template scope="scope">
                  <div>{{{'0' : '否' ,'1': '是'}[scope.row.isCameToCampus]}}</div>
                </template>
              </el-table-column> -->
              <el-table-column
                min-width="150"
                prop="visitContent"
                label="回访内容"
              >
              </el-table-column>
              <el-table-column
                min-width="100"
                label="是否成交"
              >
                <template scope="scope">
                  <div>{{scope.row.firstRegNum > 0 ? '已成交' : '未成交'}}</div>
                </template>
              </el-table-column>
              <el-table-column
                min-width="150"
                label="是否签到"
              >
                <template scope="scope">
                  <div>{{scope.row.signStatus == 1 ? '已签到': '未签到'}}</div>
                </template>
              </el-table-column>
              <el-table-column
                min-width="150"
                label="回收时间"
              >
                <template scope="scope">
                  <div>{{scope.row.recycleTime | formatTime}}</div>
                </template>
              </el-table-column>
              <el-table-column
                min-width="150"
                fixed="right"
                label="操作"
              >
                <template scope="scope">
                  <el-button
                    size="small"
                    @click="handleDetail(scope.row)"
                  >报读明细</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
        <div class="am-u-lg-12 am-cf">
          <div class="am-fr">
            <pagination
              v-bind:total="total"
              v-bind:pageNo="pageNo"
              v-bind:pageSize="pageSize"
              @paging="loadTableData"
            />
          </div>
        </div>
        <visit-detail ref="visitDetail"></visit-detail>
      </div>
    </div>

  </div>
</template>
<script>
import io from '../../lib/io'
import CustomerToolbar from './CustomerToolbar.vue'
import Pagination from '../base/Pagination.vue'
import moment from 'moment'
import VisitDetail from './VisitDetail.vue'
export default {
  data: function() {
    return {
      total: 0,
      pageSize: 10,
      pageNo: 1,
      tableData: [{}]
    }
  },
  components: {
    VisitDetail,
    CustomerToolbar,
    Pagination
  },
  watch: {},
  computed: {},
  mounted: function() {
    $(window).smoothScroll()
  },
  methods: {
    handleDetail(item) {
      this.getStudentReadClassList(item)
    },
    getStudentReadClassList({ studentId, phoneNo }) {
      io.post(
        io.studentReadClassListByPhoneNoOrId,
        {
          studentId: studentId,
          studentPhoneNo: phoneNo
        },
        ret => {
          if (ret.success) {
            this.$refs.visitDetail.tableData = ret.data
            this.$refs.visitDetail.show()
          } else {
            this.$alert(ret.desc)
          }
        }
      )
    },
    handleFind(formData) {
      this.formData = this.formatData(formData)
      this.loadTableData(1)
    },
    handleExport(formData) {
      this.formData = this.formatData(formData)
      io.downloadFile(
        io.downloadMyVisitDetail,
        Object.assign({}, this.formData, {
          pageNo: this.pageNo,
          pageSize: this.pageSize
        }),
        ret => {}
      )
    },
    loadTableData(pageNo) {
      this.pageNo = pageNo || this.pageNo || 1
      this.$showLoading()
      io.post(
        io.myVisitDetail,
        Object.assign({}, this.formData, {
          pageNo: this.pageNo,
          pageSize: this.pageSize
        }),
        ret => {
          this.$hiddenLoading()
          if (ret.success) {
            this.tableData = ret.data.list
            this.total = ret.data.total
          } else {
            this.$alert(ret.desc)
          }
        }
      )
    },
    formatData(data) {
      return {
        areaTeamId: data.areaTeamId,
        willRegCampusId: data.campusId,
        studentName: data.studentName,
        phoneNo: data.phoneNo,
        haveReg: data.haveReg,
        visitOperatorName: data.visitOperatorName,
        recycleTimeOfStart: data.recycleTime[0]
          ? moment(data.recycleTime[0]).format('YYYY-MM-DD H:mm:ss')
          : '',
        recycleTimeOfEnd: data.recycleTime[1]
          ? moment(data.recycleTime[1])
              .endOf('day')
              .format('YYYY-MM-DD H:mm:ss')
          : '',
        visitTimeOfStart: data.visitTime[0]
          ? moment(data.visitTime[0]).format('YYYY-MM-DD')
          : '',
        visitTimeOfEnd: data.visitTime[1]
          ? moment(data.visitTime[1]).format('YYYY-MM-DD')
          : ''
      }
    }
  }
}
</script>
<style lang="less" scoped>
</style>
